package com.yiyang.entity;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

/*
* 统一处理响应式的结果实体对象
* */
@Data
@Schema(name = "Result",description = "统一处理响应式的结果")
public class Result<T> {
    //响应的自定义的状态码
    @Schema(name = "code",description = "响应自定义状态码")
    private Integer code;
    //响应的提示消息
    @Schema(name = "message",description = "响应的提示消息")
    private String message;
    //定义total
    @Schema(name = "total",description = "定义total")
    private Long total;
    //响应的数据
    @Schema(name = "data",description = "响应的数据")
    private T data;

    public static <T> Result<T> success(T data){
        Result<T> result = new Result();
        result.setCode(Code.SUCCESS);
        result.setMessage("成功");
        result.setData(data);
        return result;
    }
    public static <T> Result<T> success(T data,Long total){
        Result<T> result = new Result();
        result.setCode(Code.SUCCESS);
        result.setMessage("成功");
        result.setData(data);
        result.setTotal(total);
        return result;
    }
    public static <T> Result<T> fail(){
        Result<T> result = new Result();
        result.setCode(Code.FAIL);
        result.setMessage("失败");
        return result;
    }

}
